package com.is.demo.security.service;

import cn.hutool.core.util.ObjectUtil;
import com.is.demo.generator.entity.User;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

import java.util.Collection;

/**
 * @author Will
 */
public class CustomUserDetails implements UserDetails {

    private User user;

    public CustomUserDetails(User user) {
        this.user = user;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return ObjectUtil.isNull(user)?false:true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return ObjectUtil.isNull(user)?false:true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return ObjectUtil.isNull(user)?false:true;
    }

    @Override
    public boolean isEnabled() {
        return ObjectUtil.isNull(user)?false:true;
    }
}
